package dao;
import java.util.List;

import org.hibernate.classic.Session;
import org.hibernate.Transaction;

import util.HibernateUtil;
import entity.ContasReceber;
import entity.ContasReceber;

public class ContasReceberDaoImplementation implements ContasReceberDao {

	public void save(ContasReceber contasReceber) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.save(contasReceber);
		transaction.commit();
		session.close();
	}

	public void update(ContasReceber contasReceber) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.update(contasReceber);
		transaction.commit();
		session.close();
	}

	public void delete(ContasReceber contasReceber) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.delete(contasReceber);
		transaction.commit();
		session.close();
	}

	public void consult(ContasReceber contasReceber) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		contasReceber = (ContasReceber) session.load(ContasReceber.class, new String("ContasReceber"));
	}

	public ContasReceber getContasReceber(long id) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		return (ContasReceber) session.load(ContasReceber.class, id);
	}

	@Override
	public List<ContasReceber> list() {
		Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = session.beginTransaction();
        String sql = "SELECT new ContasReceber( c.id, c.valorPago, c.juros, c.dataRecebimento, c.itemParcelaVenda) FROM ContasReceber c";
        List<ContasReceber> lista = session.createQuery(sql).list();
        transaction.commit();
        session.close();
        return lista;
	}
	
	
	
	

}
